import 'package:flutter/material.dart';
import 'package:proj_sfv/store/MyArguments.dart';
import 'package:shared_preferences/shared_preferences.dart';

class VideoSearch extends StatefulWidget {
  @override
  _VideoSearch createState() => _VideoSearch();
}

class _VideoSearch extends State<VideoSearch> {
  String _searchText = '';
  int id;
  String token;

  void _searchVideos() {
    Navigator.pushNamed(context, "/video/search/detail", arguments: MyArguments(id, token).ofSearchWords(_searchText));
  }


  @override
  void initState() {
    SharedPreferences.getInstance().then((value) {
      id = value.getInt("id");
      token = value.getString("token");
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        return false;
      },
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Padding(
                padding: EdgeInsets.only(left: 10, right: 20),
                child: SizedBox(
                  width: 280,
                  child: TextField(
                    decoration: InputDecoration(hintText: '搜索视频'),
                    onChanged: (value) => setState(() => _searchText = value),
                    onSubmitted: (value) => _searchVideos(),
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(right: 18),
                child: IconButton(
                  icon: Icon(Icons.search),
                  onPressed: _searchVideos,
                ),
              ),
            ],
          ),
        ]
      ),
    );
  }
}
